/**
 * 会话相关API接口
 */

import { request } from '@/utils/request';
import { MessageDTO } from './message';

// 类型定义
export interface Conversation {
  title: string;
  userId: string;
}

export interface ConversationDTO {
  id: string;
  createTime?: string;
  updateTime?: string;
  title: string;
  userId?: string;
  messages?: MessageDTO[];
  agentId?: number;
}

export interface ConversationCreateDTO {
  title: string;
  userId?: string;
  agentId?: number;
}

export interface ConversationUpdateDTO {
  title: string;
  userId: string;
}

// 获取会话列表
export async function getAllConversations(): Promise<ConversationDTO[]> {
  return request.get('/api/conversations/list');
}

// 获取单个会话
export async function getConversationById(id: string): Promise<ConversationDTO> {
  return request.get('/api/conversations/get', { params: { id } });
}

// 根据用户ID获取会话列表
export async function getConversationsByUserId(userId: string): Promise<ConversationDTO[]> {
  return request.get('/api/conversations/user', { params: { userId } });
}

// 创建会话
export async function createConversation(data: ConversationCreateDTO): Promise<ConversationDTO> {
  return request.post('/api/conversations/create', data);
}

// 更新会话
export async function updateConversation(id: string, data: ConversationUpdateDTO): Promise<ConversationDTO> {
  return request.put(`/api/conversations/update?id=${id}`, data);
}

// 删除会话
export async function deleteConversation(id: string): Promise<void> {
  return request.delete('/api/conversations/delete', { params: { id } });
}